#include "bullet.h"
void bullet::breakwall()
{if(posx+speed>520||posx-speed<0||posy+speed>520||posy-speed<0)
    {
        moving=false;return;
    }
    switch(direction)
    {
    case 1:
        if(maps::mmap[(posy-speed)/20][(posx)/20]==4||maps::mmap[(posy-speed)/20][(posx+4)/20]==4)
        {
            if(maps::mmap[(posy-speed)/20][(posx)/20]==4)
                maps::mmap[(posy-speed)/20][(posx)/20]=0;
            else{maps::mmap[(posy-speed)/20][(posx+4)/20]=0;}
            moving=false;//撞砖墙并且击破
        }
        if(maps::mmap[(posy-speed)/20][(posx)/20]==5||maps::mmap[(posy-speed)/20][(posx+4)/20]==5)
        {
            moving=false;//撞铁墙并消失
        }
        break;
    case 2:
        if(maps::mmap[(posy+speed)/20][(posx)/20]==4||maps::mmap[(posy+speed)/20][(posx+4)/20]==4)
        {
            if(maps::mmap[(posy+speed)/20][(posx)/20]==4)
                maps::mmap[(posy+speed)/20][(posx)/20]=0;
            else{maps::mmap[(posy+speed)/20][(posx+4)/20]=0;}
            moving=false;//撞砖墙并且击破
        }
        if(maps::mmap[(posy+speed)/20][(posx)/20]==5||maps::mmap[(posy+speed)/20][(posx+4)/20]==5)
        {
            moving=false;//撞铁墙并消失
        }
        break;
    case 3:
        if(maps::mmap[(posy+4)/20][(posx-speed)/20]==4||maps::mmap[(posy)/20][(posx-speed)/20]==4)
        {
            if(maps::mmap[(posy)/20][(posx-speed)/20]==4)
                maps::mmap[(posy)/20][(posx-speed)/20]=0;
            else{maps::mmap[(posy+4)/20][(posx-speed)/20]=0;}
            moving=false;//撞砖墙并且击破
        }
        if(maps::mmap[(posy)/20][(posx-speed)/20]==5||maps::mmap[(posy+4)/20][(posx-speed)/20]==5)
        {
            moving=false;//撞铁墙并消失
        }
        break;
    case 4:
        if(maps::mmap[(posy+4)/20][(posx+speed)/20]==4||maps::mmap[(posy)/20][(posx+speed)/20]==4)
        {
            if(maps::mmap[(posy)/20][(posx+speed)/20]==4)
                maps::mmap[(posy)/20][(posx+speed)/20]=0;
            else{maps::mmap[(posy+4)/20][(posx+speed)/20]=0;}
            moving=false;//撞砖墙并且击破
        }
        if(maps::mmap[(posy)/20][(posx+speed)/20]==5||maps::mmap[(posy+4)/20][(posx+speed)/20]==5)
        {
            moving=false;//撞铁墙并消失
        }
        break;

    }
if(posx<=280&&posx>=240&&posy>=480&&posy<=520)
{
    maps::HQ=false;
}
}
void bullet::attackenemy(int num)
{int size=39;
    for(int i=0;i<maps::enemynumber;i++)
    {if(i==num){continue;}
    switch(direction)
    {

    case 1:
      if(maps::enemyposx[i]>=posx-size&&maps::enemyposx[i]<=posx)
        {
         if(maps::enemyposy[i]+39>=posy-speed&&maps::enemyposy[i]+39<posy)
         {
            moving=false;
            maps::enemyposy[i]=560;
            maps::enemyposx[i]=560;
            return;
         }
      }
        break;
    case 2:
        if(maps::enemyposx[i]>=posx-size&&maps::enemyposx[i]<=posx)
        {
         if(maps::enemyposy[i]<=posy+speed&&maps::enemyposy[i]>=posy)
         {      moving=false;
             maps::enemyposy[i]=560;
          maps::enemyposx[i]=560;
          return;
         }
        }
        break;
    case 3:
        if(maps::enemyposy[i]>=posy-39&&maps::enemyposy[i]<=posy)
        {

            if(maps::enemyposx[i]+39>=posx-speed&&maps::enemyposx[i]<=posx)
            {
                maps::enemyposx[i]=560;
                moving =false;
                maps::enemyposy[i]=560;
                return;
            }
        }
        break;
    case 4:
        if(maps::enemyposy[i]>=posy-39&&maps::enemyposy[i]<=posy)
        {
            if(maps::enemyposx[i]<=posx+speed&&maps::enemyposx[i]>=posx)
            {
                maps::enemyposx[i]=560;
                moving =false;
                maps::enemyposy[i]=560;
                return;
            }

        }



    }



    }
    return;
};
void bullet::attackplayer()
{int size=39;
    switch(direction)
    {

    case 1:
      if(maps::myx>=posx-size&&maps::myx<=posx)
        {
         if(maps::myy+39>=posy-speed&&maps::myy+39<posy)
         {
            moving=false;
maps::playerhp-=1;
            return;
         }
      }
        break;
    case 2:
        if(maps::myx>=posx-size&&maps::myx<=posx)
        {
         if(maps::myy<=posy+speed&&maps::myy>=posy)
         {      moving=false;
maps::playerhp-=1;
          return;
         }
        }
        break;
    case 3:
        if(maps::myy>=posy-39&&maps::myy<=posy)
        {

            if(maps::myx+39>=posx-speed&&maps::myx<=posx)
            {
maps::playerhp-=1;
                moving =false;
                return;
            }
        }
        break;
    case 4:
        if(maps::myy>=posy-39&&maps::myy<=posy)
        {
            if(maps::myx<=posx+speed&&maps::myx>=posx)
            {

                moving =false;
maps::playerhp-=1;
                return;
            }

        }



    }
}
